// hyb_yl/krecovery/pages/edit_recovery/edit_recovery.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: []
  },
  remove: function (e) {
    var index = e.currentTarget.dataset.index;
    var list = this.data.list;
    list.splice(index, 1);
    this.setData({
      list: list
    })
  },
  // 设置开关
  switch:function(e){
    var id = e.currentTarget.dataset.id;
    var zid = e.currentTarget.dataset.zid;
    app.util.request({
      'url':"entry/wxapp/green.edit_shtype",
      data:{
        id:id,
        zid:zid
      },
      success:function(res)
      {
        that.getGreen();
      }
    })
  },
  remove:function(e)
  {
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '提示',
      content:"是否确认删除",
      success:function(con)
      {
        if(con.confirm)
        {
          app.util.request({
            'url':"entry/wxapp/green.del_shtype",
            data:{
              id:id
            },
            success:function(res)
            {
              that.getGreen();
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var zid = options.zid;
    var that = this;
    that.setData({
      zid:zid
    })
    
  },
  getGreen:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/green.getsh_type",
      data:{
        zid:that.data.zid
      },
      success:function(res){
        that.setData({
          list:res.data
        })
      }
    })
  },
  // 编辑
  edit:function(e){
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/createtstype/createtstype?id='+e.currentTarget.dataset.id+'&zid='+this.data.zid,
    })
  },
  add:function(e){
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/createtstype/createtstype?zid='+this.data.zid,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getGreen()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})